﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace FileSharing
{
    public class Downloads
    {
        List<DownloadTask> DownloadList = new List<DownloadTask>();
        Diretorio Directory;

        public IPEndPoint LocalAddress { get; set; }

        public Downloads(Diretorio dir, IPEndPoint localAddress)
        {
            Directory = dir;
            LocalAddress = localAddress;
        }

        public void AddTask(DownloadTask task)
        {
            DownloadList.Add(task);
        }

        public string IncomingPath()
        {
            return Directory.Location;
        }

        public void Close()
        {
            foreach (DownloadTask t in DownloadList)
                t.Close();
        }

        public DownloadItem[] GetDownloadCollection()
        {
            DownloadItem[] col = new DownloadItem[DownloadList.Count];

            for (int i = 0; i < DownloadList.Count; i++)
            {
                col[i] = DownloadList[i].GetDownloadInfo();
            }

            return col;
        }

        public void DownloadCompleted(DownloadTask task)
        {
            Directory.Refresh();
        }
    }
}
